package cn.com.generaldata.os.service.indicator_evaluation.sustainable_development;

import cn.com.generaldata.jsme_indicator_system.entity.IndicatorEvaluation;
import cn.com.generaldata.os.service.indicator_constant.ProvinceIndicatorConstant;
import cn.com.generaldata.os.service.indicator_evaluation.IndicatorEvaluationCalculateService;
import cn.com.generaldata.os.util.BeanMapper;
import cn.com.generaldata.os.vo.IndicatorAccountVO;

/**
 * 城镇恩格尔系数评估指标计算类.
 */
public class CityEngelCoefficientCalculateService extends IndicatorEvaluationCalculateService {

	private String cityEngel = ProvinceIndicatorConstant.CITY_ENGEL;
	// private String[] citys=ProvinceIndicatorConstant.CITYS;
	private Integer yearBase = 2001;

	@Override
	protected Double calculate(IndicatorEvaluation indicator, IndicatorAccountVO indicatorAccountVO) {
		IndicatorAccountVO iav = BeanMapper.map(indicatorAccountVO, IndicatorAccountVO.class);
		int num = 0;
		Double now = 0d;
		Double sum = 0d;
		Integer inputOrAccountingMaxYear = getInputOrAccountingMaxYear(cityEngel, indicatorAccountVO.getAreaId());
		if (inputOrAccountingMaxYear == null) {
			return 0d;
		}
		for (int i = yearBase; i <= inputOrAccountingMaxYear; i++)
		{
			iav.setYear(i);
			Double xi = getInputOrAccountingIndicatorValue(iav, iav.getYear(), cityEngel);
			if (i == indicatorAccountVO.getYear()) {
				now = xi;
			}
			if (xi != null && !(Double.valueOf(0).equals(xi))) {
				num++;
			}
			sum += xi;
		}
		return (sum / num) / now;
	}

}
